 
package scm.rawMaterialPurchasing.managedbean;

import crm.salesOrderProcessing.entity.ProductEntity;
import crm.salesOrderProcessing.session.ProductManageSessionBean;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
 
@ManagedBean(name="bomChooseAProductManagedBean")
@ViewScoped
public class BomChooseAProductManagedBean implements Serializable{
  
    @EJB
    ProductManageSessionBean productManageSessionBean;
    private ProductEntity selectedProduct;
    private String selectedProductName;
    
    
    public BomChooseAProductManagedBean() {
    }
    
    public List<String> getAllProductsName(){
       return productManageSessionBean.getProductNames();
    }
    
    public void confirmProduct(ActionEvent e) throws IOException { 
        
        selectedProduct=productManageSessionBean.getProductByName(getSelectedProductName());
        
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedProduct", selectedProduct);
        FacesContext.getCurrentInstance().getExternalContext().redirect("bomManage.xhtml");
    }

    public ProductEntity getSelectedProduct() {
        return selectedProduct;
    }

    public void setSelectedProduct(ProductEntity selectedProduct) {
        this.selectedProduct = selectedProduct;
    }

    public String getSelectedProductName() {
        return selectedProductName;
    }

    public void setSelectedProductName(String selectedProductName) {
        this.selectedProductName = selectedProductName;
    }
}
